#!/bin/bash

echo "========================================"
echo "  启动股票分析后端服务"
echo "========================================"
echo ""

# 检查 Python 是否安装
if ! command -v python3 &> /dev/null; then
    echo "[错误] 未检测到 Python，请先安装 Python 3.9+"
    exit 1
fi

echo "[1/3] 检查依赖..."
pip3 show fastapi > /dev/null 2>&1
if [ $? -ne 0 ]; then
    echo "[提示] 检测到缺少依赖，正在安装..."
    pip3 install -r requirements.txt
fi

echo ""
echo "[2/3] 初始化数据库..."
python3 database.py

echo ""
echo "[3/3] 启动 API 服务..."
echo ""
echo "========================================"
echo "  API 服务已启动"
echo "  访问地址: http://localhost:8000"
echo "  API 文档: http://localhost:8000/docs"
echo "========================================"
echo ""

python3 main.py

